<template>
  <div id="home">
    <div class="main-page">
      <el-container>
        <!-- 侧边栏 -->
        <el-aside width="200px">
          <h1 class="logo">千锋智慧</h1>

          <el-menu
            default-active="1-4-1"
            class="el-menu-vertical-demo"
            @open="handleOpen"
            @close="handleClose"
            :collapse="isCollapse"
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span slot="title">导航一</span>
              </template>

              <el-menu-item-group>
                <span slot="title">分组一</span>
                <el-menu-item index="1-1">选项1</el-menu-item>
                <el-menu-item index="1-2">选项2</el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-menu-item index="2">
              <i class="el-icon-menu"></i>
              <span slot="title">导航二</span>
            </el-menu-item>

            <el-menu-item index="3" disabled>
              <i class="el-icon-document"></i>
              <span slot="title">导航三</span>
            </el-menu-item>
          </el-menu>
        </el-aside>

        <el-container>
          <!-- 顶部 -->
          <el-header>
            <el-row type="flex" class="row-bg" justify="space-between">
              <el-col :span="6"
                ><div class="grid-content bg-purple">
                  <el-radio-group
                    v-model="isCollapse"
                    style="margin-bottom: 20px"
                  >
                    <el-radio-button :label="false">展开</el-radio-button>
                    <el-radio-button :label="true">收起</el-radio-button>
                  </el-radio-group>
                </div></el-col
              >
              <el-col :span="6"
                ><div class="grid-content bg-purple-light">
                  千锋管理系统
                </div></el-col
              >
              <el-col :span="6"
                ><div class="grid-content bg-purple">
                  <el-avatar :size="40" @error="errorHandler">
                    <img src="../imgs/girl.jpg" />
                  </el-avatar>
                  <span>欢迎您：</span>
                  <span class="nickname">{{ userInfo.nickname }}</span>
                  <span class="quit" @click="quit">退出</span>
                </div></el-col
              >
            </el-row>
          </el-header>
          <!-- 主体 -->
          <el-main>
            <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item>管理首页</el-breadcrumb-item>
            </el-breadcrumb>
            <el-table :data="tableData" border style="width: 100%">
              <el-table-column prop="date" label="登录账号" width="200">
              </el-table-column>
              <el-table-column prop="name" label="上次登录ip" width="300">
              </el-table-column>
              <el-table-column prop="address" label="上次登录时间" width="246">
              </el-table-column>
              <el-table-column prop="name" label="本次登录ip" width="300">
              </el-table-column>
              <el-table-column prop="address" label="本次登录时间" width="246">
              </el-table-column>
            </el-table>
          </el-main>
        </el-container>
      </el-container>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import { getloginlog } from "@/api/index";
export default {
  data() {
    return {
      isCollapse: true,
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    };
  },
  computed: {
    ...mapState(["userInfo"]),
  },
  mounted() {
    getloginlog().then((res) => {
      console.log(res);
    });
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    errorHandler() {
      return true;
    },
    quit(){
      //1.清除本地token和userInfo
      localStorage.removeItem("stu_token")
      localStorage.removeItem("stu-info")
      //2.返回登录页面
      this.$router.push("/login")
    }
  },
};
</script>

<style>
.el-header,
.el-footer {
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 50px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.el-row {
  margin-bottom: 20px;
}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 0;
}

.logo {
  height: 60px;
}

.el-breadcrumb {
  line-height: 30px;
  font-size: 20px;
  padding-bottom: 8px;
}

element.style {
  height: 40px;
  width: 40px;
  line-height: 40px;
}

.el-avatar {
  vertical-align: middle;
}

.quit {
  cursor: pointer;
  color: green;
}
</style>